package algorithm.easy;

import java.util.ArrayList;
import java.util.List;

public class Merg2363eSimilarItems {


    public List<List<Integer>> mergeSimilarItems(int[][] items1, int[][] items2) {
        int[] temp = new int[1001];

        for (int[] ints1 : items1) {
            temp[ints1[0]] += ints1[1];
        }
        for (int[] ints1 : items2) {
            temp[ints1[0]] += ints1[1];
        }
        List<List<Integer>> res = new ArrayList<>();
        for (int i = 0; i < temp.length; i++) {
            if (temp[i] != 0) {
                ArrayList<Integer> list = new ArrayList<>();
                list.add(i);
                list.add(temp[i]);
                res.add(list);
            }
        }
        return res;
    }
}
